#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class WeightUnionSet {
public:
	WeightUnionSet(int n) :fa(n + 1),val(n + 1) {
		for (int i = 0; i <= n; i++) {
			fa[i] = i;
			val[i] = 0;
		}
	}

	int get(int x) {
		if (fa[x] == x) return x;
		int root = get(fa[x]);
		val[x] = (val[x] + val[fa[x]]) % 2;
		return fa[x] = root;
	}

	void merge(int a,int b,int t){
		int aa = get(a), bb = get(b);
		if (aa == bb) return;
		val[aa] = (t - val[a] + val[b] + 2) % 2;
		fa[aa] = bb;
	}

	vector<int> fa, val;
};

struct Data {
	int a, b, c;
};


int main()
{
	int n, m;
	cin >> n >> m;
	vector<Data> arr(m);
	WeightUnionSet u(n);
	for (int i = 0; i < m; i++){
		cin >> arr[i].a >> arr[i].b >> arr[i].c;
	}
	sort(arr.begin(), arr.end(), [&](const Data& a, const Data& b) {
		return a.c > b.c; //按c排序
		});

	int ans = 0;
	for (int i = 0; i < m; i++) {
		int a = arr[i].a, b = arr[i].b, c = arr[i].c;
		if (u.get(a) == u.get(b)) {
			if ((u.val[a] + u.val[b]) % 2 == 0) {
				ans = c;
				break;
			}
		}
		else u.merge(a, b, 1); //a b分配在不同房间
	}
	cout << ans << endl;
	return 0;
}


//测试数据
//4 6
//1 4 2534
//2 3 3512
//1 2 28351
//1 3 6618
//2 4 1805
//3 4 128840.